package com.company.emallbackend.controller;

import com.company.emallbackend.common.Result;
import com.company.emallbackend.entity.dto.LoginDTO;
import com.company.emallbackend.entity.dto.RegisterDTO;
import com.company.emallbackend.entity.dto.ResetPwdDTO;
import com.company.emallbackend.entity.vo.LoginVo;
import com.company.emallbackend.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author hanlijian
 * @create 2023-01-11-11:39
 */
@RestController
@RequestMapping("user")
@Api(tags = "登录注册忘记密码")
@Slf4j
public class WebController {
    
    @Resource
    private IUserService userService;

    /**
     * 用户登录
     * @param loginDTO
     * @return
     */
    @PostMapping("login")
    @ApiOperation("用户登录")
    public Result login(@RequestBody LoginDTO loginDTO){
        LoginVo loginVo=userService.login(loginDTO);
        return Result.success(loginVo);
    }

    /**
     * 用户注册
     * @param registerDTO
     * @return
     */
    @PostMapping("register")
    @ApiOperation("用户注册")
    public Result register(@RequestBody RegisterDTO registerDTO){
        userService.register(registerDTO);
        return Result.success();
    }

    /**
     * 邮箱验证
     * @param email
     * @param type
     * @return
     */
    @PostMapping("email")
    @ApiOperation("邮箱验证(type类型注册和重置密码) 1.register 2.restPassword)")
    public Result sendEmail(@RequestParam String email,@RequestParam String  type){
        userService.sendEmail(email,type);
        return Result.success();
    }

    /**
     * 重置密码
     * @param resetPwdDTO
     * @return
     */
    @PostMapping("password/rest")
    @ApiOperation("重置密码")
    public Result passwordRest(@RequestBody ResetPwdDTO resetPwdDTO){
        userService.passwordRest(resetPwdDTO);
        return Result.success("重置成功,密码为:123");
    }

    
}
